import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const router = new VueRouter({
	linkActiveClass: 'router-link-active',
	routes: [{
			path: '/',
			redirect: '/longin'
		},
		{
			path: '/longin',
			name: 'longin',
			meta: {
				isTab: false,
				title: '首页'

			},
			component: () => import('../components/index.vue')
			
		},
		{
			path: '/classify',
			name: 'classify',
			component: () => import('../components/classify.vue')
		},
		{
			path: '/gwc',
			name: 'gwc',
			meta: {
				isTab: false,
				title: '购物车'

			},
			component: () => import('../components/gwc.vue'),

			//   children: [{
			// 	path: 'cheng',
			// 	name:'cheng',
			// 	component: () => import('../components/cheng.vue')
			// }]
		},
		{
			path: '/gwc/order',
			name: 'order',
			meta: {
				isTab: false,
				title: '订单消息'
		
			},
		component: () => import('../components/my/order.vue'),
		},
		{
			path: '/gwc/addressListy',
			name: 'addressListy',
			meta: {
				isTab: true,
				title: '收货地址'
		
			},
		component: () => import('../components/my/addressListy.vue'),
		},

		{
			path: '/my',
			name: 'my',
			meta: {
				isTab: false, //判断是否是tab页,tab页有底部Tabbar并且没有左上角返回按钮
				title: '个人中心' //配置导航栏上的title
			},
			component: () => import('../components/my.vue')
		},
		{
			path: '/gwc/amend',
			name: 'amend',
			meta: {
				isTab: true,
				title: '购物车'
			
			},
			component: () => import('../components/amend.vue')
		},
		{
			path: '/gwc/cheng',
			name: 'cheng',
			meta: {
				isTab: true,
				title: '购物车'

			},
			component: () => import('../components/cheng.vue')
		},
		{
			path:'/denglu',
			name:'denglu',
			meta:{
				isTab: true,
				title: '登录',
			},
			component: () => import('../components/denglu.vue')
		},
		{
			path:'/member',
			name:'member',
			meta:{
				isTab: true,
				title: '登录',
			},
			component: () => import('../components/member.vue')
		},
		{
			path:'/register',
			name:'register',
			meta:{
				isTab: true,
				title: '注册',
			},
			component: () => import('../components/register.vue')
		},
		
		{
			path: '/particulars/pinglun',
			name: 'pinglun',
			meta:{
				isTab: true,
				title: '全部评论',
			},
			component: () => import('../components/pinglun.vue')
		},
		{
			path: '/particulars',
			name: 'particulars',
			meta:{
				isTab: true,
				title: '详情页',
			},
			component: () => import("../components/particulars.vue")
		},
	]
})


router.beforeEach((to, from, next) => {

	if (to.name == 'show' && !Boolean(localStorage.getItem('list')) || to.name == 'xueshu' && !Boolean(
			localStorage.getItem('list'))) {
		if (confirm("页面需要登陆后访问,要去登陆吗?")) {
			next({
				path: '/deng'
			})
		} else {
			next(false)
		}
	} else {
		next()
	}
})



export default router
